package cn.cvs.servlet.storagerecord;

import cn.cvs.pojo.StorageRecord;
import cn.cvs.service.StorageRecordService;
import cn.cvs.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ViewStorageServlet", urlPatterns = "/sys/storageRecord/view")
public class ViewStorageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        int id = Integer.parseInt ( request.getParameter ( "id" ) );
        StorageRecordService storageRecordService= (StorageRecordService) SpringUtil.getBean ( "stoageRecordService" );

        StorageRecord storageRecord = storageRecordService.getStorageRecordById ( id );
        request.setAttribute ( "storageRecord",storageRecord );
        request.getRequestDispatcher ( "/WEB-INF/jsp/storageRecord/view.jsp" ).forward ( request,response );
    }
}
